﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Utility;
using BUS;

public partial class Administrator_doanhnghiep : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
         {
             load_data();
         }
    }

    private void load_data()
    {
        pager.PageSize = 15;
        Criteria c = new Criteria();
        if (txt_tendoanhnghiep.Text != "")
        {
            c.add(Condition.AND, Tbl_DoanhNghiep_Columns.TenDN, Condition.LIKE,
               txt_tendoanhnghiep.Text);
        }
        int total = 0;
        Tbl_DoanhNghiep_Collection dnCollection =
            Tbl_DoanhNghiep_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            Tbl_DoanhNghiep_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = dnCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_DoanhNghiep_Entities dn = (Tbl_DoanhNghiep_Entities)e.Item.DataItem;
            HyperLink hyp_tendn = (HyperLink)e.Item.FindControl("hyp_tendn");
            Literal lit_diachi = (Literal)e.Item.FindControl("lit_diachi");
            Literal lit_sdt = (Literal)e.Item.FindControl("lit_sdt");
            HyperLink hyp_website = (HyperLink)e.Item.FindControl("hyp_website");
            HyperLink hyp_madoanhnghiep = (HyperLink)e.Item.FindControl("hyp_madoanhnghiep");
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");

            hyp_tendn.NavigateUrl = "~/Administrator/doanhnghiep_chitiet.aspx?id=" + dn.STT.ToString();
            lit_diachi.Text = dn.DiaChi;
            lit_sdt.Text = dn.SDT;
            hyp_website.Text =  dn.WebSite;
            hyp_website.NavigateUrl = "http://" + dn.WebSite;
            lit_stt.Text = dn.STT.ToString();
        }
    }

    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        load_data();
    }
}
